#import "FTNavgationController.h"


#import "UIBarButtonItem+add.h"
@interface FTNavgationController ()
@end
@implementation FTNavgationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    //背影颜色,ios15以上会失效
    self.navigationBar.barTintColor = mainColor;
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc]init];
        [appearance configureWithOpaqueBackground];
        appearance.backgroundColor = mainColor;
        [appearance setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:20]}];
        self.navigationBar.standardAppearance = appearance;
        self.navigationBar.scrollEdgeAppearance = appearance;
    } else {
        // Fallback on earlier versions
    }
    
    //图标的颜色
    self.navigationBar.tintColor = [UIColor grayColor];
    self.navigationBar.translucent = NO;
    
   //标题颜色
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:20]}];
    
    //统一设置返回图标(能保留侧滑返回功能)
//    [[UINavigationBar appearance]setBackIndicatorImage:[UIImage imageNamed:@"goBack_white120x120"]];
//    [[UINavigationBar appearance]setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"goBack_white120x120"]];
    //设置文字的向上偏移用来隐藏
//    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, 0) forBarMetrics:UIBarMetricsDefault];
    //设备图标渲染颜色
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//    if (@available(iOS 14.0, *)) {
//        self.navigationItem.backButtonDisplayMode = UINavigationItemBackButtonDisplayModeMinimal;
//    } else {
//        // Fallback on earlier versions
//    }
    
}
////统一设置返回按钮
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{

    //如果不是根VC
    if (self.childViewControllers.count>0) {
        viewController.hidesBottomBarWhenPushed=YES;
        UIViewController *vc = self.childViewControllers.lastObject;
//        vc.navigationItem.backBarButtonItem.title = @"  ";
        vc.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"    " style:UIBarButtonItemStylePlain target:self action:@selector(popToVC)];
        vc.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
        //用这个返回按钮大一点
//        UIBarButtonItem *backItem = [UIBarButtonItem itemWithImage:@"goBack_white120x120" ImageHighLight:@"goBack_white120x120" Target:self Seletor:@selector(popToVC) CGRect:CGRectMake(0, 0, 40, 40)];
//        viewController.navigationItem.leftBarButtonItem = backItem;

    }
    [super pushViewController:viewController animated:animated];
   

}
- (void)popToVC{
    
    [self popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(BOOL)shouldAutorotate{
    return [self.topViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}

@end
